package pwr.online.cow.model;

import java.util.LinkedList;

public class Board {
	private LinkedList<Position> mHistory;
	private LinkedList<BoardUpdateListener> mListeners;

	public Board() {
		mHistory = new LinkedList<Position>();
		mListeners = new LinkedList<BoardUpdateListener>();
	}
	
	public void addHistoryEntry(Position position) {
		mHistory.add(position);
		for (BoardUpdateListener l : mListeners)
			l.OnBoardHistoryAdded(position);
	}
	
	public int getHistoryCount() {
		return mHistory.size();
	}
	
	public Position getHistoryAtTime(int time) {
		if (time < 0 || time > getHistoryCount())
			return null;
		return mHistory.get(time);
	}
	
	public void clearBoard() {
		mHistory.clear();
		for (BoardUpdateListener l : mListeners)
			l.OnBoardHistoryCleared();
	}
	
	public void addListener(BoardUpdateListener listener) {
		mListeners.add(listener);
	}
}
